package com.java.com.syun.bio;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class BioClient {
    public static void main(String[] args) {
        Socket socket = null;
        OutputStream out = null;
        InputStream in = null;
        try {
            // 与Server建立连接
            socket = new Socket("127.0.0.1", 9000);
            // 发送数据
            out = socket.getOutputStream();
            out.write("Hello".getBytes());
            out.flush();
            // 完成发送数据
            socket.shutdownOutput();
            // 接收数据
            in = socket.getInputStream();
            byte[] buffer = new byte[1024];
            // 阻塞式读取
            while (in.read(buffer) != -1) {
                System.out.println("读取相应数据：>> " + new String(buffer));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            IOCloseUtils.close(socket,out,in);
        }
    }
}